package FuncionalOptionsTest

import (
	"errors"
	"fmt"
)

type Act struct {
	Id   int
	Name string
}

type CheckFunc func(act *Act) error

func CheckId(id int) CheckFunc {
	return func(act *Act) error {
		if id == act.Id {
			return errors.New("匹配的ID")
		}
		return nil
	}
}

func CheckName(name string) CheckFunc {
	return func(act *Act) error {
		if name == "pig" {
			act.Name = "update"
			return nil
		}
		return nil
	}
}

func Exec(ctx string, fns ...CheckFunc) error {
	aModel := Act{Id: 10, Name: ctx}
	for k, fn := range fns {
		if k == 0 {
			fn(&aModel)
		} else {
			go fn(&aModel)
		}
		if ok := fn(&aModel); ok != nil {
			fmt.Println("出现了需要过滤的东西")
			return ok
		}
	}
	fmt.Println("我执行我的东西")
	fmt.Println(aModel)
	return nil
}
